package com.android.happymall.view.recycleview;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;

/**
 * Created by Administrator on 2017/3/30.
 */

public class CustomRecycleView extends RecyclerView {
    private boolean isScrollEnabled;
    public CustomRecycleView(Context context) {
        super(context);
        initView();
    }

    public CustomRecycleView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initView();
    }

    public CustomRecycleView(Context context, @Nullable AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        initView();
    }

    private boolean isTop;

    private void initView() {
        addOnScrollListener(new OnScrollListener() {
            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                if (dy < 0) {
                    isTop = true;
                    if (top_View != null) {
                        top_View.setVisibility(VISIBLE);
                    }
                } else {
                    isTop = false;
                    if (top_View != null) {
                        top_View.setVisibility(INVISIBLE);
                    }
                }

            }
        });
    }

    private ImageView top_View;
    private int type = -1;
    public void GetToTop(ImageView v, int i) {
        this.top_View = v;
        this.type = i;
        v.setVisibility(INVISIBLE);
        v.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                LayoutManager layoutManager = getLayoutManager();
                layoutManager.scrollToPosition(0);
            }
        });
    }

}
